package cn.edu.java.io.inputstream.filterinputstream;

import lombok.SneakyThrows;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class DataInputStreamDemo {
    @SneakyThrows
    public static void main(String[] args) {
        String fileName = "input/data.bin";

        // 创建一个 DataInputStream 对象
        DataInputStream dataInputStream = new DataInputStream(new FileInputStream(fileName));

        // 读取整数
        int intValue = dataInputStream.readInt();
        System.out.println("读取整数: " + intValue);

        // 读取浮点数
        double doubleValue = dataInputStream.readDouble();
        System.out.println("读取浮点数: " + doubleValue);

        // 读取布尔值
        boolean booleanValue = dataInputStream.readBoolean();
        System.out.println("读取布尔值: " + booleanValue);

        // 读取字符串
        String stringValue = dataInputStream.readUTF();
        System.out.println("读取字符串: " + stringValue);

        dataInputStream.close();
    }
}

